﻿using AIStudio.Wpf.Business.Bussiness;
using AIStudio.Wpf.Business.IBussiness;
using AIStudio.Wpf.Client.ViewModels;
using AIStudio.Wpf.Client.Views;
using AIStudio.Wpf.PrismDragablzExtensions.Regions;
using Dragablz;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Unity;
using System.Windows;
using Accelerider.Extensions.Mvvm;
using AIStudio.Wpf.Base_Manage;

namespace AIStudio.Wpf.Client
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            var window = Container.Resolve<MainWindow>();
            return window;
        }

        protected override void InitializeShell(Window shell)
        {
            //登录
            LoginWindow login = new LoginWindow();
            if (login.ShowDialog() == false)
            {
                if (Application.Current != null)
                {
                    Application.Current.Shutdown();
                }
                return;
            }

            base.InitializeShell(shell);
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<IDataProvider, ApiDataProvider>();
            containerRegistry.RegisterSingleton<IOperator, Operator>();
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            var mainWindowModule = typeof(MainWindowModule);
            moduleCatalog.AddModule(new ModuleInfo()
            {
                ModuleName = mainWindowModule.Name,
                ModuleType = mainWindowModule.AssemblyQualifiedName,
                InitializationMode = InitializationMode.WhenAvailable
            });

            var base_ManageModule = typeof(Base_ManageModule);
            moduleCatalog.AddModule(new ModuleInfo()
            {
                ModuleName = base_ManageModule.Name,
                ModuleType = base_ManageModule.AssemblyQualifiedName,
                InitializationMode = InitializationMode.WhenAvailable
            });
        }

        protected override void ConfigureViewModelLocator()
        {
            //base.ConfigureViewModelLocator();
            ViewModelLocationProvider.SetDefaultViewModelFactory(new ViewModelResolver(() => Container)
                .UseDefaultConfigure()
                .ResolveViewModelForView);

            ViewModelLocationProvider.Register<MainWindow, MainWindowViewModel>();

        }

        protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
        {
            base.ConfigureRegionAdapterMappings(regionAdapterMappings);
            regionAdapterMappings.RegisterMapping(typeof(TabablzControl), Container.Resolve<TabablzControlRegionAdapter>());
        }
    }
}
